package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.query.NearStationsQuery;
import cn.tedu.charging.common.pojo.vo.StationDetailVO;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 站场 桩 枪接口全都集中在设备controller
 */
@RestController
@Slf4j
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @GetMapping("/device/station/near")
    public JsonResult<List<StationInfoVO>> nearStations(NearStationsQuery query) {
        //1.控制层要什么 业务就返回什么
        List<StationInfoVO> vos = deviceService.nearStations(query);
        return JsonResult.ok(vos);
    }

    //查询某个充电站详情包括站场信息以及站场关联的枪数据
    @GetMapping("/device/station/detail/{stationId}")
    public JsonResult<StationDetailVO> detailStation(@PathVariable Integer stationId) {
        StationDetailVO vo=deviceService.detailStation(stationId);
        return JsonResult.ok(vo);
    }

    //订单调用设备检查枪是否可用
    @GetMapping("/device/gun/check")
    public JsonResult<Boolean> checkGun(@RequestParam("gunId") Integer gunId) {
        //应该根据枪的id调用业务层 TODO
        //1. 使用gunId 查询gunPo
        //2. 判断 只要status不是1 就不可用 return status==1
        return JsonResult.ok(true);
    }
}
